package com.sleep.psy.external_server.business.adjustment.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qcloud.cos.model.PutObjectResult;
import com.sleep.psy.external_server.business.adjustment.entity.AdjustmentPlanDetails;
import com.sleep.psy.external_server.business.adjustment.entity.vo.PlanSleepDetailsReq;
import com.sleep.psy.external_server.business.adjustment.mapper.AdjustmentPlanDetailsMapper;
import com.sleep.psy.external_server.business.adjustment.service.AdjustmentPlanDetailsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sleep.psy.external_server.business.adjustment.service.AdjustmentPlanService;
import com.sleep.psy.external_server.business.evaluation.entity.EvaluationRecord;
import com.sleep.psy.external_server.business.evaluation.entity.EvaluationReport;
import com.sleep.psy.external_server.business.psy.entity.PsyBaseVideo;
import com.sleep.psy.external_server.business.psy.entity.PsySection;
import com.sleep.psy.external_server.business.psy.mapper.PsySectionMapper;
import com.sleep.psy.external_server.business.psy.service.PsyBaseVideoService;
import com.sleep.psy.external_server.business.psy.service.PsySectionService;
import com.sleep.psy.external_server.business.resourse.entity.ResourceAudio;
import com.sleep.psy.external_server.business.resourse.service.ResourceAudioService;
import com.sleep.psy.external_server.business.sys.entity.SysProjectConfig;
import com.sleep.psy.external_server.business.sys.service.SysProjectConfigService;
import com.sleep.psy.external_server.constants.Constant;
import com.sleep.psy.external_server.constants.MySqlConstant;
import com.sleep.psy.external_server.property.AudioProperties;
import com.sleep.psy.external_server.result.Result;
import com.sleep.psy.external_server.result.ResultUtil;
import com.sleep.psy.external_server.service.FileService;
import com.sleep.psy.external_server.utils.AudioCureUtils;
import com.sleep.psy.external_server.utils.AudioUtils;
import com.sleep.psy.external_server.utils.DateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.File;
import java.io.FileOutputStream;
import java.util.*;
import java.util.stream.Collectors;

/**
 * <p>
 * 调节方案详情 服务实现类
 * </p>
 *
 * @author wenliguo
 * @since 2025-08-12
 */
@Service
public class AdjustmentPlanDetailsServiceImpl extends ServiceImpl<AdjustmentPlanDetailsMapper, AdjustmentPlanDetails> implements AdjustmentPlanDetailsService {

    protected Logger logger = LoggerFactory.getLogger(AdjustmentPlanDetailsService.class);

    @Autowired
    private PsySectionMapper psySectionMapper;

    @Autowired
    private PsyBaseVideoService psyBaseVideoService;

    @Autowired
    private AdjustmentPlanService planService;

    @Autowired
    private AdjustmentPlanDetailsMapper planDetailsMapper;

    @Autowired
    private PsySectionService psySectionService;

    @Autowired
    private AudioProperties audioProperties;

    @Autowired
    private ResourceAudioService resourceAudioService;

    @Autowired
    private FileService fileService;

    @Autowired
    private SysProjectConfigService configService;

    /**
     * 生成调节方案
     *
     * @param userId     用户id
     * @param planId     计划id
     * @param record     测评记录
     * @param report     测评报告
     * @param isAutoSend 是否自动下发方案：1-是；0-否
     * @author wenliguo
     * @date 2025/8/16 11:45
     */
    @Override
    public List<AdjustmentPlanDetails> generateSleepPlanDetail(Long userId, Long planId, EvaluationRecord record, EvaluationReport report, Integer isAutoSend) {

        //21天每日一课
        List<PsyBaseVideo> baseVideos = psyBaseVideoService.selectBaseVideoByBsiType(MySqlConstant.PSY_BASE_VIDEO_BSI_TYPE_3);
        if (baseVideos.isEmpty()) {
            logger.info("未查询到基础视频");
            return null;
        }

        //先生成基础的21天
        int num = 1;
        for (int i = 0; i < baseVideos.size(); i++) {
            AdjustmentPlanDetails planDetails = new AdjustmentPlanDetails();
            planDetails.setPlanId(planId);
            planDetails.setTitle("第" + num + "天");
            if (i < 4) {
                planDetails.setTopic(Constant.TOPIC_1);
            } else if (i < 7) {
                planDetails.setTopic(Constant.TOPIC_2);
            } else if (i < 11) {
                planDetails.setTopic(Constant.TOPIC_3);
            } else {
                planDetails.setTopic(Constant.TOPIC_4);
            }
            planDetails.setAudioSort(i + 1);
            planDetails.setSleepUrl(selectSleepBaseVideo());
            if (MySqlConstant.IS_AUTO_SEND_1.equals(isAutoSend)) {
                planDetails.setStatus(MySqlConstant.STATUS_1);
            } else {
                planDetails.setStatus(MySqlConstant.STATUS_0);
            }
            planDetailsMapper.insert(planDetails);
            num++;
        }

        List<String> errorInfo = getErrorInfo(report.getId());
        List<String> cognition = cognition(errorInfo);
        int kgrNum = getKgrNum(errorInfo);
        //用户选择的症状
        String types = record.getTypes();
        List<String> video = getVideo(types, cognition, kgrNum);

        List<AdjustmentPlanDetails> detailsList = selectPlanDetailsByPlanId(planId);
        for (int i = 0; i < detailsList.size(); i++) {
            AdjustmentPlanDetails details = new AdjustmentPlanDetails();
            details.setId(detailsList.get(i).getId());
            details.setPlayList(video.get(i));
            planDetailsMapper.updateById(details);
        }

        return detailsList;
    }

    /**
     * 处理文件合并音频
     * @author wenliguo
     * @date 2025/6/10 11:42
     * @param newFilePath 新文件名称(本地地址)
     * @param playList 音频碎屏
     * @return java.lang.String
     */
    private String dealFile(String newFilePath, String playList, Long userId) {
        logger.info("处理合并音频");
        String[] playArr = playList.split(",");
        List<String> files = new ArrayList<>();
        for (String s : playArr) {
            ResourceAudio audio = resourceAudioService.selectAudioByCode(s);
            if (null == audio) {
                return null;
            }

            String cosRegion = audio.getCosRegion();
            String bucketName = audio.getBucketName();
            String cosKey = audio.getCosKey();

            byte[] objectByte = fileService.getObjectByte(cosRegion, bucketName, cosKey);

            SysProjectConfig config = configService.selectByKey(audioProperties.getOriginFilePath());

            String path = config.getConfigValue() + System.currentTimeMillis() + audioProperties.getFileSuffix();
            try (FileOutputStream outputStream = new FileOutputStream(path)) {
                // 写入byte数组到文件
                outputStream.write(objectByte);
                logger.info("文件写入成功");
            } catch (Exception e) {
                logger.error("写入文件时发生错误", e);
                return null;
            }

            files.add(path);
        }

        //合并成功后上传到云
        String name = userId + "/" + DateUtils.formatByDate(new Date(), DateUtils.DATE_FORMAT) + audioProperties.getFileSuffix();
        String fileName = audioProperties.getCosKey() + name;
        try {
            AudioUtils.combine(audioProperties.getMergeCommand(), files, newFilePath);
            PutObjectResult result = fileService.fileUpload(audioProperties.getCosRegion(), audioProperties.getBucketName(), newFilePath, fileName);
            if (null == result) {
                return null;
            }
            //https://zhongyixinyuan-1302199733.cos.ap-beijing.myqcloud.com/sm/user_audio/15910635391/A1.mp3
            return audioProperties.getUrlFix() + fileName;
        } catch (Exception e) {
            logger.error("合成音频失败", e);
            logger.error("合成音频失败对象:{}", playList);
            return null;
        } finally {
            //无论合并成功还是失败都需要删除源文件
            for (String file : files) {
                File originFile = new File(file);
                if (originFile.exists()) {
                    originFile.delete();
                }
            }
            File newFile = new File(newFilePath);
            if (newFile.exists()) {
                newFile.delete();
            }

        }
    }

    /**
     * 通过计划id获取具体计划
     * @author wenliguo
     * @date 2025/8/16 11:45
     * @param planId 计划id
     * @return java.util.List<com.sleep.psy.main_server.business2.adjustment.entity.AdjustmentPlanDetails>
     */
    @Override
    public List<AdjustmentPlanDetails> selectPlanDetailsByPlanId(Long planId) {
        QueryWrapper<AdjustmentPlanDetails> wrapper = new QueryWrapper<>();
        wrapper.eq("plan_id", planId)
                .orderByAsc("audio_sort");
        return planDetailsMapper.selectList(wrapper);
    }

    /**
     * 获取每日的调节详情
     * @author wenliguo
     * @date 2025/8/16 14:40
     * @param req 请求
     * @return com.sleep.psy.main_server.result.Result
     */
    @Override
    public Result selectDetail(PlanSleepDetailsReq req) {
        Long id = req.getId();
        Long userId = req.getUserId();

        AdjustmentPlanDetails planDetails = planDetailsMapper.selectById(id);
        if (null == planDetails) {
            logger.info("计划详情不存在");
            return ResultUtil.success();
        }

        PsyBaseVideo baseVideo = psyBaseVideoService.selectVideByBsiTypeAndSort(MySqlConstant.PSY_BASE_VIDEO_BSI_TYPE_3, planDetails.getAudioSort());

        if (null != baseVideo) {
            planDetails.setEveryDayUrl(baseVideo.getVideoUrl());
        }

        if (null != planDetails.getAudioUrl()) {
            logger.info("音频存在直接返回");
            return ResultUtil.success(planDetails);
        }

        SysProjectConfig config = configService.selectByKey(audioProperties.getNewFilePath());

        String newFilePath = config.getConfigValue() + planDetails.getPlanId() + "_" + planDetails.getAudioSort() + audioProperties.getFileSuffix();
        String url = dealFile(newFilePath, planDetails.getPlayList(), userId);
        if (null != url) {
            planDetails.setAudioUrl(url);
            planDetailsMapper.updateById(planDetails);
        }

        return ResultUtil.success(planDetails);

    }

    /**
     * 记录所有的异常选项
     * @author wenliguo
     * @date 2025/6/9 14:39
     * @param reportId 报告id
     * @return java.util.ArrayList<java.lang.String>
     */
    private List<String> getErrorInfo(Long reportId) {

        List<String> errorInfo = new ArrayList<>();

        List<PsySection> sections = psySectionService.selectSectionByReportId(reportId);
        if (sections.isEmpty()) {
            return errorInfo;
        }


        for (PsySection section : sections) {
            Double value = section.getValue();
            String valueStr = value + "";

            if ("1.0".equals(valueStr)) {
                errorInfo.add(section.getSortIndex() + "");
            }
        }

        logger.info("有问题的答案个数:{},列表:{}", errorInfo.size(), JSON.toJSONString(errorInfo));
        return errorInfo;

    }

    /**
     * 认知处理
     * @author wenliguo
     * @date 2025/6/9 14:46
     * @param errorInfo 异常选项
     * @return java.util.List<java.lang.String>
     */
    private List<String> cognition(List<String> errorInfo) {
        List<String> rzList = new ArrayList<>();
        if (errorInfo.size() >= 41) {
            //大于41个 只取前41个认知
            for (int i = 0; i < 41; i++) {
                rzList.add("RZ" + (Integer.parseInt(errorInfo.get(i)) < 10 ? "0" + errorInfo.get(i) : errorInfo.get(i)));
            }
        } else if (errorInfo.size() >= 16) {
            //认知不足 41个 但是>=16个  需要在补充里面 补充到41个
            int buAdd = 41 - errorInfo.size();
            for (String errNum : errorInfo) {
                rzList.add("RZ" + (Integer.parseInt(errNum) < 10 ? "0" + errNum : errNum));
            }
            if (buAdd < 11) {
                for (int i = 0; i < buAdd; i++) {
                    rzList.add("RB" + (i + 1 < 10 ? "0" + (i + 1) : (i + 1)));
                }
            }
            if (buAdd >= 11) {
                for (int i = 0; i < 11; i++) {
                    rzList.add("RB" + (i + 1 < 10 ? "0" + (i + 1) : (i + 1)));
                }
                int num = buAdd - 11;
                for (int i = 0; i < num; i++) {
                    rzList.add("RZ" + (Integer.parseInt(errorInfo.get(i)) < 10 ? "0" + errorInfo.get(i) : errorInfo.get(i)));
                }
            }
        } else {
            //认知不足 16个  需要在认知补充里面 循环补充
            for (String errNum : errorInfo) {
                rzList.add("RZ" + (Integer.parseInt(errNum) < 10 ? "0" + errNum : errNum));
            }
            int buAdd = 41 - errorInfo.size();

            for (int j = 1; j <= buAdd; j++) {
                if (j % 11 == 0) {
                    rzList.add("RB11");
                } else {
                    rzList.add("RB" + (j % 11 < 10 ? "0" + j % 11 : j % 11));
                }
            }
        }

        logger.info("认知个数:{}", rzList.size());
        return rzList;
    }

    /**
     * 获取抗干扰个数
     * @author wenliguo
     * @date 2025/6/9 14:54
     * @param errorInfo 异常选项
     * @return int
     */
    private int getKgrNum(List<String> errorInfo) {

        /**
         * 抗干扰技术用于勾选以下条目时使用。
         * 我睡眠的时候任何干扰都不能有；
         * 我觉得我一晚上似睡非睡；
         * 失眠是工作、环境等外在因素造成的；
         */
        int num = 0;
        if (errorInfo.contains("18")) {
            num += 1;
        }
        if (errorInfo.contains("20")) {
            num += 1;
        }
        if (errorInfo.contains("30")) {
            num += 1;
        }

        logger.info("干扰个数:{}", num);
        return num;
    }

    /**
     * 音频碎片
     * @author wenliguo
     * @date 2025/6/9 16:01
     * @param types 症状
     * @param rzList 认知
     * @param kgrNum 获取抗干扰个数
     * @return java.util.List<java.lang.String>
     */
    private List<String> getVideo(String types, List<String> rzList, int kgrNum) {
        List<String> selList = Arrays.asList(types.split(","));

        /**
         * 入睡困难(1)＞中间醒(2)＞眠浅(3)＞梦多(4)＞早醒(5)＞日间症状(6)
         */
        Map<String,Integer> cureMap = new HashMap<>();  //每种情况有几种音频
        cureMap.put("1", 5);
        cureMap.put("2", 2);
        cureMap.put("3", 1);
        cureMap.put("4", 1);
        cureMap.put("5", 3);
        cureMap.put("6", 1);

        Map<String,String> cureAudioMap = new HashMap<>();
        cureAudioMap.put("1", "A");
        cureAudioMap.put("2", "B");
        cureAudioMap.put("3", "C");
        cureAudioMap.put("4", "D");
        cureAudioMap.put("5", "E");
        cureAudioMap.put("6", "F");

        List<String> cureFirt = new ArrayList<>();
        cureFirt.add("04_A_01");
        cureFirt.add("04_B_01");
        cureFirt.add("04_C_01");
        cureFirt.add("04_D_01");
        cureFirt.add("04_E_01");
        cureFirt.add("04_F_01");

        Map<String,String> cureFirtMap = new HashMap<>();
        cureFirtMap.put("1", "04_A_01");
        cureFirtMap.put("2", "04_B_01");
        cureFirtMap.put("3", "04_C_01");
        cureFirtMap.put("4", "04_D_01");
        cureFirtMap.put("5", "04_E_01");
        cureFirtMap.put("6", "04_F_01");

        List<String> arrayList = new ArrayList<>();

        int size = selList.size();
        if (size == 1) {
            logger.info("1个症状");
            arrayList = getOneSymptom(cureMap, cureAudioMap, cureFirtMap, cureFirt, selList, rzList, kgrNum);
        } else if (size == 2) {
            logger.info("2个症状");
            arrayList = getTwoSymptom(cureMap, cureAudioMap, cureFirtMap, cureFirt, selList, rzList, kgrNum);
        } else if (size == 3) {
            logger.info("3个症状");
            arrayList = getThreeSymptom(cureMap, cureAudioMap, cureFirtMap, cureFirt, selList, rzList, kgrNum);
        } else if (size == 4) {
            logger.info("4个症状");
            arrayList = getFourSymptom(cureMap, cureAudioMap, cureFirtMap, cureFirt, selList, rzList, kgrNum);
        } else if (size == 5) {
            logger.info("5个症状");
            arrayList = getFiveSymptom(cureMap, cureAudioMap, cureFirtMap, cureFirt, selList, rzList, kgrNum);
        } else if (size == 6) {
            logger.info("6个症状");
            arrayList = getSixSymptom(cureMap, cureAudioMap, cureFirtMap, cureFirt, selList, rzList, kgrNum);
        }
        return arrayList;
    }

    /**
     * 一个症状的21天调节
     * 只有一个主症，
     * D1-D4对症治疗（主症1）；
     * D5-D7对症治疗依次选3个（入睡困难＞中间醒＞眠浅＞梦多＞早醒＞日间症状）;
     * D8-D11，对症治疗（主症1）；
     * D12-D13依次选最后2个（入睡困难＞中间醒＞眠浅＞梦多＞早醒＞日间症状）；
     * D14同上；
     * @author wenliguo
     * @date 2025/6/9 15:17
     * @return java.util.List<java.lang.String>
     */
    private List<String> getOneSymptom(Map<String, Integer> cureMap, Map<String, String> cureAudioMap, Map<String, String> cureFirtMap, List<String> cureFirt, List<String> selList, List<String> rzList, int kgrNum) {

        List<String> sel1 = new ArrayList<>();
        /**
         * 主症 出现九次
         *  D1-D4对症治疗（主症1）  4
         *  D8-D11，对症治疗（主症1）  ；   4
         *  D14 对症治疗（主症1   1
         *
         *  for 循环 取余 循环往复  比如取5  1 2 3 4 5 1 2 3 4
         */
        Integer forNum = cureMap.get(selList.get(0));
        String cureAudioStr = cureAudioMap.get(selList.get(0));

        for (int j = 1; j <= 9; j++) {
            if (j % forNum == 0) {
                sel1.add("04_" + cureAudioStr + "_0" + forNum);
            } else {
                sel1.add("04_" + cureAudioStr + "_0" + j % forNum);
            }
        }

        /**
         * 针对其它症状
         */
        cureFirt.remove(cureFirtMap.get(selList.get(0)));

        List<String> sel14 = new ArrayList<>();
        //---------------------------第1天--------------------------

        sel14.add(sel1.get(0));


        //---------------------------第2天--------------------------

        sel14.add(sel1.get(1));

        //---------------------------第3天--------------------------

        sel14.add(sel1.get(2));

        //---------------------------第4天--------------------------

        sel14.add(sel1.get(3));

        //---------------------------第5天--------------------------

        sel14.add(cureFirt.get(0));

        //---------------------------第6天--------------------------

        sel14.add(cureFirt.get(1));

        //---------------------------第7天--------------------------

        sel14.add(cureFirt.get(2));

        //---------------------------第8天--------------------------

        sel14.add(sel1.get(4));

        //---------------------------第9天--------------------------
        sel14.add(sel1.get(5));

        //---------------------------第10天--------------------------

        sel14.add(sel1.get(6));

        //---------------------------第11天--------------------------

        sel14.add(sel1.get(7));

        //---------------------------第12天--------------------------

        sel14.add(cureFirt.get(3));

        //---------------------------第13天--------------------------

        sel14.add(cureFirt.get(4));

        //---------------------------第14天--------------------------

        sel14.add(sel1.get(8));
        return get21Info(rzList, kgrNum, sel14);
    }

    /**
     * 两个症状的21天调节
     * 两个主症，D1-D2对症治疗（主症1）；
     * D3-D4对症治疗（主症2）；
     * D5-D8对症治疗4个（入睡困难＞中间醒＞眠浅＞梦多＞早醒＞日间症状）；
     * D9、D11、D13对症治疗（主症1）;
     * D10、D12、D14对症治疗（主症2）;
     * @author wenliguo
     * @date 2025/6/9 15:25
     * @return java.util.List<java.lang.String>
     */
    private List<String> getTwoSymptom(Map<String, Integer> cureMap, Map<String, String> cureAudioMap, Map<String, String> cureFirtMap, List<String> cureFirt, List<String> selList, List<String> rzList, int kgrNum) {
        /**
         *  内部排序   "8","5","6","1"  ->[1, 5, 6, 8]
         */
        Collections.sort(selList);

        List<String> sel1 = new ArrayList<>();
        List<String> sel2 = new ArrayList<>();

        /**
         * 两个主症 每个出现（2 + 3）
         *  for 循环 取余 循环往复
         */

        Integer forNum1 = cureMap.get(selList.get(0));
        String cureAudioStr1 = cureAudioMap.get(selList.get(0));

        Integer forNum2 = cureMap.get(selList.get(1));
        String cureAudioStr2 = cureAudioMap.get(selList.get(1));

        for (int j = 1; j <= 5; j++) {
            if (j % forNum1 == 0) {
                sel1.add("04_" + cureAudioStr1 + "_0" + forNum1);
            } else {
                sel1.add("04_" + cureAudioStr1 + "_0" + j % forNum1);
            }
        }

        for (int j = 1; j <= 5; j++) {
            if (j % forNum2 == 0) {
                sel2.add("04_" + cureAudioStr2 + "_0" + forNum2);
            } else {
                sel2.add("04_" + cureAudioStr2 + "_0" + j % forNum2);
            }
        }

        /**
         * 针对其它症状
         */
        cureFirt.remove(cureFirtMap.get(selList.get(0)));
        cureFirt.remove(cureFirtMap.get(selList.get(1)));

        List<String> sel14 = new ArrayList<>();
        //---------------------------第1天--------------------------

        sel14.add(sel1.get(0));

        //---------------------------第2天--------------------------

        sel14.add(sel1.get(1));

        //---------------------------第3天--------------------------

        sel14.add(sel2.get(0));

        //---------------------------第4天--------------------------

        sel14.add(sel2.get(1));


        //---------------------------第5天--------------------------

        sel14.add(cureFirt.get(0));

        //---------------------------第6天--------------------------

        sel14.add(cureFirt.get(1));

        //---------------------------第7天--------------------------

        sel14.add(cureFirt.get(2));

        //---------------------------第8天--------------------------

        sel14.add(cureFirt.get(3));

        //---------------------------第9天--------------------------

        sel14.add(sel1.get(2));

        //---------------------------第10天--------------------------

        sel14.add(sel2.get(2));

        //---------------------------第11天--------------------------

        sel14.add(sel1.get(3));

        //---------------------------第12天--------------------------

        sel14.add(sel2.get(3));

        //---------------------------第13天--------------------------

        sel14.add(sel1.get(4));

        //---------------------------第14天--------------------------

        sel14.add(sel2.get(4));

        return get21Info(rzList, kgrNum, sel14);

    }

    /**
     * 三个症状的21天调节
     * 三个主症；D1-D3对症治疗（主症1）；
     * D4-D6对症治疗（主症2）；
     * D7-D9对症治疗（主症3）；
     * D10-D12对症治疗（主症1、2、3）；
     * D13-D14对症治疗按顺序选2个（入睡困难＞中间醒＞眠浅＞梦多＞早醒＞日间症状）；
     * @author wenliguo
     * @date 2025/6/9 15:28
     * @return java.util.List<java.lang.String>
     */
    private List<String> getThreeSymptom(Map<String, Integer> cureMap, Map<String, String> cureAudioMap, Map<String, String> cureFirtMap, List<String> cureFirt, List<String> selList, List<String> rzList, int kgrNum) {
        /**
         *  内部排序   "8","5","6","1"  ->[1, 5, 6, 8]
         */
        Collections.sort(selList);

        List<String> sel1 = new ArrayList<>();
        List<String> sel2 = new ArrayList<>();
        List<String> sel3 = new ArrayList<>();

        /**
         * 两个主症 每个出现（3 + 1）
         *  for 循环 取余 循环往复
         */

        Integer forNum1 = cureMap.get(selList.get(0));
        String cureAudioStr1 = cureAudioMap.get(selList.get(0));

        Integer forNum2 = cureMap.get(selList.get(1));
        String cureAudioStr2 = cureAudioMap.get(selList.get(1));

        Integer forNum3 = cureMap.get(selList.get(2));
        String cureAudioStr3 = cureAudioMap.get(selList.get(2));

        for (int j = 1; j <= 4; j++) {
            if (j % forNum1 == 0) {
                sel1.add("04_" + cureAudioStr1 + "_0" + forNum1);
            } else {
                sel1.add("04_" + cureAudioStr1 + "_0" + j % forNum1);
            }
        }

        for (int j = 1; j <= 4; j++) {
            if (j % forNum2 == 0) {
                sel2.add("04_" + cureAudioStr2 + "_0" + forNum2);
            } else {
                sel2.add("04_" + cureAudioStr2 + "_0" + j % forNum2);
            }
        }

        for (int j = 1; j <= 4; j++) {
            if (j % forNum3 == 0) {
                sel3.add("04_" + cureAudioStr3 + "_0" + forNum3);
            } else {
                sel3.add("04_" + cureAudioStr3 + "_0" + j % forNum3);
            }
        }

        /**
         * 针对其它症状
         */
        cureFirt.remove(cureFirtMap.get(selList.get(0)));
        cureFirt.remove(cureFirtMap.get(selList.get(1)));
        cureFirt.remove(cureFirtMap.get(selList.get(2)));

        List<String> sel14 = new ArrayList<>();
        //---------------------------第1天--------------------------

        sel14.add(sel1.get(0));

        //---------------------------第2天--------------------------

        sel14.add(sel1.get(1));

        //---------------------------第3天--------------------------

        sel14.add(sel1.get(2));

        //---------------------------第4天--------------------------

        sel14.add(sel2.get(0));

        //---------------------------第5天--------------------------

        sel14.add(sel2.get(1));

        //---------------------------第6天--------------------------

        sel14.add(sel2.get(2));

        //---------------------------第7天--------------------------

        sel14.add(sel3.get(0));

        //---------------------------第8天--------------------------

        sel14.add(sel3.get(1));

        //---------------------------第9天--------------------------

        sel14.add(sel3.get(2));

        //---------------------------第10天--------------------------

        sel14.add(sel1.get(3));

        //---------------------------第11天--------------------------

        sel14.add(sel2.get(3));

        //---------------------------第12天--------------------------

        sel14.add(sel3.get(3));

        //---------------------------第13天--------------------------

        sel14.add(cureFirt.get(0));

        //---------------------------第14天--------------------------

        sel14.add(cureFirt.get(1));

        return get21Info(rzList, kgrNum, sel14);
    }

    /**
     * 四个症状的21天调节
     * 四个主症：D1-D3对症治疗（主症1）；
     * D4-D6对症治疗（主症2）；
     * D7-D9对症治疗（主症3）；
     * D10-D12对症治疗（主症4）；
     * D13-D14对症治疗按顺序选2个（入睡困难＞中间醒＞眠浅＞梦多＞早醒＞日间症状）；
     * @author wenliguo
     * @date 2025/6/9 15:30
     * @return java.util.List<java.lang.String>
     */
    private List<String> getFourSymptom(Map<String, Integer> cureMap, Map<String, String> cureAudioMap, Map<String, String> cureFirtMap, List<String> cureFirt, List<String> selList, List<String> rzList, int kgrNum) {

        /**
         *  内部排序   "8","5","6","1"  ->[1, 5, 6, 8]
         */
        Collections.sort(selList);

        List<String> sel1 = new ArrayList<>();
        List<String> sel2 = new ArrayList<>();
        List<String> sel3 = new ArrayList<>();
        List<String> sel4 = new ArrayList<>();
        /**
         * 两个主症 每个出现3
         *  for 循环 取余 循环往复
         */

        Integer forNum1 = cureMap.get(selList.get(0));
        String cureAudioStr1 = cureAudioMap.get(selList.get(0));

        Integer forNum2 = cureMap.get(selList.get(1));
        String cureAudioStr2 = cureAudioMap.get(selList.get(1));

        Integer forNum3 = cureMap.get(selList.get(2));
        String cureAudioStr3 = cureAudioMap.get(selList.get(2));

        Integer forNum4 = cureMap.get(selList.get(3));
        String cureAudioStr4 = cureAudioMap.get(selList.get(3));

        for (int j = 1; j <= 3; j++) {
            if (j % forNum1 == 0) {
                sel1.add("04_" + cureAudioStr1 + "_0" + forNum1);
            } else {
                sel1.add("04_" + cureAudioStr1 + "_0" + j % forNum1);
            }
        }

        for (int j = 1; j <= 3; j++) {
            if (j % forNum2 == 0) {
                sel2.add("04_" + cureAudioStr2 + "_0" + forNum2);
            } else {
                sel2.add("04_" + cureAudioStr2 + "_0" + j % forNum2);
            }
        }

        for (int j = 1; j <= 3; j++) {
            if (j % forNum3 == 0) {
                sel3.add("04_" + cureAudioStr3 + "_0" + forNum3);
            } else {
                sel3.add("04_" + cureAudioStr3 + "_0" + j % forNum3);
            }
        }

        for (int j = 1; j <= 3; j++) {
            if (j % forNum4 == 0) {
                sel4.add("04_" + cureAudioStr4 + "_0" + forNum4);
            } else {
                sel4.add("04_" + cureAudioStr4 + "_0" + j % forNum4);
            }
        }

        /**
         * 针对其它症状
         */
        cureFirt.remove(cureFirtMap.get(selList.get(0)));
        cureFirt.remove(cureFirtMap.get(selList.get(1)));
        cureFirt.remove(cureFirtMap.get(selList.get(2)));
        cureFirt.remove(cureFirtMap.get(selList.get(3)));

        List<String> sel14 = new ArrayList<>();
        //---------------------------第1天--------------------------

        sel14.add(sel1.get(0));

        //---------------------------第2天--------------------------

        sel14.add(sel1.get(1));

        //---------------------------第3天--------------------------

        sel14.add(sel1.get(2));

        //---------------------------第4天--------------------------

        sel14.add(sel2.get(0));

        //---------------------------第5天--------------------------

        sel14.add(sel2.get(1));

        //---------------------------第6天--------------------------

        sel14.add(sel2.get(2));

        //---------------------------第7天--------------------------

        sel14.add(sel3.get(0));

        //---------------------------第8天--------------------------

        sel14.add(sel3.get(1));

        //---------------------------第9天--------------------------

        sel14.add(sel3.get(2));

        //---------------------------第10天--------------------------

        sel14.add(sel4.get(0));

        //---------------------------第11天--------------------------

        sel14.add(sel4.get(1));

        //---------------------------第12天--------------------------

        sel14.add(sel4.get(2));

        //---------------------------第13天--------------------------

        sel14.add(cureFirt.get(0));

        //---------------------------第14天--------------------------

        sel14.add(cureFirt.get(1));

        return get21Info(rzList, kgrNum, sel14);

    }

    /**
     * 5个症状的21天调节
     * 五个主症：D1-D3对症治疗（主症1）；
     * D4-D6对症治疗（主症2）；
     * D7-D8对症治疗（主症3）；
     * D9-D10对症治疗（主症4）；
     * D11-D12对症治疗（主症5）；
     * D13对症治疗按顺序选1个（入睡困难＞中间醒＞眠浅＞梦多＞早醒＞日间症状）；
     * D14对症治疗（主症1）；
     * 主症1  4个
     * 主症2  3个
     * 主症3  2个
     * 主症4  2个
     * 主症5  2个
     * @author wenliguo
     * @date 2025/6/9 15:32
     * @return java.util.List<java.lang.String>
     */
    private List<String> getFiveSymptom(Map<String, Integer> cureMap, Map<String, String> cureAudioMap, Map<String, String> cureFirtMap, List<String> cureFirt, List<String> selList, List<String> rzList, int kgrNum) {
        /**
         *  内部排序   "8","5","6","1"  ->[1, 5, 6, 8]
         */
        Collections.sort(selList);

        List<String> sel1 = new ArrayList<>();
        List<String> sel2 = new ArrayList<>();
        List<String> sel3 = new ArrayList<>();
        List<String> sel4 = new ArrayList<>();
        List<String> sel5 = new ArrayList<>();
        /**
         * 两个主症 每个出现3
         *  for 循环 取余 循环往复
         */

        Integer forNum1 = cureMap.get(selList.get(0));
        String cureAudioStr1 = cureAudioMap.get(selList.get(0));

        Integer forNum2 = cureMap.get(selList.get(1));
        String cureAudioStr2 = cureAudioMap.get(selList.get(1));

        Integer forNum3 = cureMap.get(selList.get(2));
        String cureAudioStr3 = cureAudioMap.get(selList.get(2));

        Integer forNum4 = cureMap.get(selList.get(3));
        String cureAudioStr4 = cureAudioMap.get(selList.get(3));

        Integer forNum5 = cureMap.get(selList.get(4));
        String cureAudioStr5 = cureAudioMap.get(selList.get(4));

        for (int j = 1; j <= 4; j++) {
            if (j % forNum1 == 0) {
                sel1.add("04_" + cureAudioStr1 + "_0" + forNum1);
            } else {
                sel1.add("04_" + cureAudioStr1 + "_0" + j % forNum1);
            }
        }

        for (int j = 1; j <= 3; j++) {
            if (j % forNum2 == 0) {
                sel2.add("04_" + cureAudioStr2 + "_0" + forNum2);
            } else {
                sel2.add("04_" + cureAudioStr2 + "_0" + j % forNum2);
            }
        }

        for (int j = 1; j <= 2; j++) {
            if (j % forNum3 == 0) {
                sel3.add("04_" + cureAudioStr3 + "_0" + forNum3);
            } else {
                sel3.add("04_" + cureAudioStr3 + "_0" + j % forNum3);
            }
        }

        for (int j = 1; j <= 2; j++) {
            if (j % forNum4 == 0) {
                sel4.add("04_" + cureAudioStr4 + "_0" + forNum4);
            } else {
                sel4.add("04_" + cureAudioStr4 + "_0" + j % forNum4);
            }
        }

        for (int j = 1; j <= 2; j++) {
            if (j % forNum5 == 0) {
                sel5.add("04_" + cureAudioStr5 + "_0" + forNum5);
            } else {
                sel5.add("04_" + cureAudioStr5 + "_0" + j % forNum5);
            }
        }

        /**
         * 针对其它症状
         */
        cureFirt.remove(cureFirtMap.get(selList.get(0)));
        cureFirt.remove(cureFirtMap.get(selList.get(1)));
        cureFirt.remove(cureFirtMap.get(selList.get(2)));
        cureFirt.remove(cureFirtMap.get(selList.get(3)));
        cureFirt.remove(cureFirtMap.get(selList.get(4)));

        List<String> sel14 = new ArrayList<>();
        //---------------------------第1天--------------------------

        sel14.add(sel1.get(0));

        //---------------------------第2天--------------------------

        sel14.add(sel1.get(1));

        //---------------------------第3天--------------------------

        sel14.add(sel1.get(2));

        //---------------------------第4天--------------------------

        sel14.add(sel2.get(0));

        //---------------------------第5天--------------------------

        sel14.add(sel2.get(1));

        //---------------------------第6天--------------------------

        sel14.add(sel2.get(2));

//			//---------------------------第7天--------------------------

        sel14.add(sel3.get(0));

        //---------------------------第8天--------------------------

        sel14.add(sel3.get(1));

        //---------------------------第9天--------------------------

        sel14.add(sel4.get(0));

        //---------------------------第10天--------------------------

        sel14.add(sel4.get(1));

        //---------------------------第11天--------------------------

        sel14.add(sel5.get(0));

        //---------------------------第12天--------------------------

        sel14.add(sel5.get(1));

        //---------------------------第13天--------------------------

        sel14.add(cureFirt.get(0));

        //---------------------------第14天--------------------------

        sel14.add(sel1.get(3));

        return get21Info(rzList, kgrNum, sel14);
    }


    /**
     * 6个症状的21天调节
     * 六个主症：D1-D3对症治疗（主症1）；
     * D4-D6对症治疗（主症2）；
     * D7-D8对症治疗（主症3）；
     * D9-D10对症治疗（主症4）；
     * D11-D12对症治疗（主症5）；
     * D13-D14对症治疗（主症6）。
     * 主症1  3个
     * 主症2  3个
     * 主症3  2个
     * 主症4  2个
     * 主症5  2个
     * 主症6  2个
     * @author wenliguo
     * @date 2025/6/9 15:35
     * @return java.util.List<java.lang.String>
     */
    private List<String> getSixSymptom(Map<String, Integer> cureMap, Map<String, String> cureAudioMap, Map<String, String> cureFirtMap, List<String> cureFirt, List<String> selList, List<String> rzList, int kgrNum) {
        /**
         *  内部排序   "8","5","6","1"  ->[1, 5, 6, 8]
         */
        Collections.sort(selList);

        List<String> sel1 = new ArrayList<>();
        List<String> sel2 = new ArrayList<>();
        List<String> sel3 = new ArrayList<>();
        List<String> sel4 = new ArrayList<>();
        List<String> sel5 = new ArrayList<>();
        List<String> sel6 = new ArrayList<>();
        /**
         * 两个主症 每个出现3
         *  for 循环 取余 循环往复
         */

        Integer forNum1 = cureMap.get(selList.get(0));
        String cureAudioStr1 = cureAudioMap.get(selList.get(0));

        Integer forNum2 = cureMap.get(selList.get(1));
        String cureAudioStr2 = cureAudioMap.get(selList.get(1));

        Integer forNum3 = cureMap.get(selList.get(2));
        String cureAudioStr3 = cureAudioMap.get(selList.get(2));

        Integer forNum4 = cureMap.get(selList.get(3));
        String cureAudioStr4 = cureAudioMap.get(selList.get(3));

        Integer forNum5 = cureMap.get(selList.get(4));
        String cureAudioStr5 = cureAudioMap.get(selList.get(4));

        Integer forNum6 = cureMap.get(selList.get(5));
        String cureAudioStr6 = cureAudioMap.get(selList.get(5));

        for (int j = 1; j <= 3; j++) {
            if (j % forNum1 == 0) {
                sel1.add("04_" + cureAudioStr1 + "_0" + forNum1);
            } else {
                sel1.add("04_" + cureAudioStr1 + "_0" + j % forNum1);
            }
        }

        for (int j = 1; j <= 3; j++) {
            if (j % forNum2 == 0) {
                sel2.add("04_" + cureAudioStr2 + "_0" + forNum2);
            } else {
                sel2.add("04_" + cureAudioStr2 + "_0" + j % forNum2);
            }
        }

        for (int j = 1; j <= 2; j++) {
            if (j % forNum3 == 0) {
                sel3.add("04_" + cureAudioStr3 + "_0" + forNum3);
            } else {
                sel3.add("04_" + cureAudioStr3 + "_0" + j % forNum3);
            }
        }

        for (int j = 1; j <= 2; j++) {
            if (j % forNum4 == 0) {
                sel4.add("04_" + cureAudioStr4 + "_0" + forNum4);
            } else {
                sel4.add("04_" + cureAudioStr4 + "_0" + j % forNum4);
            }
        }

        for (int j = 1; j <= 2; j++) {
            if (j % forNum5 == 0) {
                sel5.add("04_" + cureAudioStr5 + "_0" + forNum5);
            } else {
                sel5.add("04_" + cureAudioStr5 + "_0" + j % forNum5);
            }
        }

        for (int j = 1; j <= 2; j++) {
            if (j % forNum6 == 0) {
                sel6.add("04_" + cureAudioStr6 + "_0" + forNum6);
            } else {
                sel6.add("04_" + cureAudioStr6 + "_0" + j % forNum6);
            }
        }

        /**
         * 针对其它症状
         */
        cureFirt.remove(cureFirtMap.get(selList.get(0)));
        cureFirt.remove(cureFirtMap.get(selList.get(1)));
        cureFirt.remove(cureFirtMap.get(selList.get(2)));
        cureFirt.remove(cureFirtMap.get(selList.get(3)));
        cureFirt.remove(cureFirtMap.get(selList.get(4)));
        cureFirt.remove(cureFirtMap.get(selList.get(5)));

        List<String> sel14 = new ArrayList<>();
        //---------------------------第1天--------------------------
        sel14.add(sel1.get(0));

        //---------------------------第2天--------------------------

        sel14.add(sel1.get(1));

        //---------------------------第3天--------------------------

        sel14.add(sel1.get(2));

        //---------------------------第4天--------------------------

        sel14.add(sel2.get(0));

        //---------------------------第5天--------------------------

        sel14.add(sel2.get(1));

        //---------------------------第6天--------------------------

        sel14.add(sel2.get(2));

        //---------------------------第7天--------------------------

        sel14.add(sel3.get(0));

        //---------------------------第8天--------------------------

        sel14.add(sel3.get(1));

        //---------------------------第9天--------------------------

        sel14.add(sel4.get(0));

        //---------------------------第10天--------------------------

        sel14.add(sel4.get(1));

        //---------------------------第11天--------------------------

        sel14.add(sel5.get(0));

        //---------------------------第12天--------------------------

        sel14.add(sel5.get(1));

        //---------------------------第13天--------------------------

        sel14.add(sel6.get(0));

        //---------------------------第14天--------------------------

        sel14.add(sel6.get(1));

        return get21Info(rzList, kgrNum, sel14);
    }

    public List<String> get21Info(List<String> rzList, Integer kgrNum, List<String> sel14) {


        //---------------------------第1天--------------------------
        List<String> lisAudio1 = new ArrayList<>();
        lisAudio1.add("01_A_00"); //指导语
        lisAudio1.add("01_A_01");  //低阻抗1
        lisAudio1.add("02_A_01");  //病史回顾
        lisAudio1.add(sel14.get(0));  //主症1-第一次
        lisAudio1.add(rzList.get(0));  //认知1
        lisAudio1.add(rzList.get(1));  //认知2
        lisAudio1.add("10_A_01"); //唤醒


        //---------------------------第2天--------------------------
        List<String> lisAudio2 = new ArrayList<>();
        lisAudio2.add("01_A_00"); //指导语
        lisAudio2.add("01_A_02");  //低阻抗2
        lisAudio2.add(sel14.get(1));  //主症1-第二次
        lisAudio2.add(rzList.get(2));  //认知3
        lisAudio2.add(rzList.get(3));  //认知4
        lisAudio2.add(rzList.get(4));  //认知5
        lisAudio2.add("09_A_01");  //疗后体验1
        lisAudio2.add("10_A_01"); //唤醒

        //---------------------------第3天--------------------------
        List<String> lisAudio3 = new ArrayList<>();
        lisAudio3.add("01_A_00"); //指导语
        lisAudio3.add("01_A_01");  //低阻抗1
        lisAudio3.add(sel14.get(2));  //主症1-第三次
        lisAudio3.add(rzList.get(5));  //认知6
        lisAudio3.add(rzList.get(6));  //认知7
        lisAudio3.add("07_A_01");  //行为1
        lisAudio3.add("09_A_02"); //疗后体验2
        lisAudio3.add("10_A_01"); //唤醒

        //---------------------------第4天--------------------------
        List<String> lisAudio4 = new ArrayList<>();
        lisAudio4.add("01_A_00"); //指导语
        lisAudio4.add("01_A_02");  //低阻抗2
        lisAudio4.add(sel14.get(3));  //主症2-第一次
        lisAudio4.add(rzList.get(7));  //认知8
        lisAudio4.add(rzList.get(8));  //认知9
        lisAudio4.add("07_A_02");  //行为2
        lisAudio4.add("09_A_03"); //疗后体验3
        lisAudio4.add("10_A_01"); //唤醒


        //---------------------------第5天--------------------------
        List<String> lisAudio5 = new ArrayList<>();
        lisAudio5.add("01_A_00"); //指导语
        lisAudio5.add("01_A_01");  //低阻抗1
        lisAudio5.add(sel14.get(4));  //主症2-第二次
        lisAudio5.add(rzList.get(9));  //认知10
        lisAudio5.add(rzList.get(10));  //认知11
        lisAudio5.add("07_A_03");  //行为3
        lisAudio5.add("08_A_01");  //信心增强
        lisAudio5.add("09_A_04"); //疗后体验4
        lisAudio5.add("10_A_01"); //唤醒

        //---------------------------第6天--------------------------
        List<String> lisAudio6 = new ArrayList<>();
        lisAudio6.add("01_A_00"); //指导语
        lisAudio6.add("01_A_02");  //低阻抗2
        lisAudio6.add(sel14.get(5));  //主症2-第三次
        lisAudio6.add(rzList.get(11));  //认知12
        lisAudio6.add(rzList.get(12));  //认知13
        lisAudio6.add("09_A_01"); //疗后体验1
        lisAudio6.add("10_A_01"); //唤醒

        //---------------------------第7天--------------------------
        List<String> lisAudio7 = new ArrayList<>();
        lisAudio7.add("01_A_00"); //指导语
        lisAudio7.add("01_A_01");  //低阻抗1
        lisAudio7.add(sel14.get(6));  //主症3-第一次
        lisAudio7.add(rzList.get(13));  //认知14
        lisAudio7.add(rzList.get(14));  //认知15

        if (kgrNum > 0) {
            lisAudio7.add("06_A_01"); //抗干扰
        }

        lisAudio7.add("09_A_02"); //疗后体验2
        lisAudio7.add("10_A_01"); //唤醒

        //---------------------------第8天--------------------------
        List<String> lisAudio8 = new ArrayList<>();
        lisAudio8.add("01_A_00"); //指导语
        lisAudio8.add("01_A_02");  //低阻抗2
        lisAudio8.add(sel14.get(7));  //主症3-第二次
        lisAudio8.add(rzList.get(15));  //认知16
        lisAudio8.add(rzList.get(16));  //认知17
        lisAudio8.add("07_A_04");  //行为4
        lisAudio8.add("08_A_01");  //信心增强
        lisAudio8.add("10_A_01"); //唤醒

        //---------------------------第9天--------------------------
        List<String> lisAudio9 = new ArrayList<>();
        lisAudio9.add("01_A_00"); //指导语
        lisAudio9.add("01_A_01");  //低阻抗1
        lisAudio9.add(sel14.get(8));  //主症4-第一次
        lisAudio9.add(rzList.get(17));  //认知18
        lisAudio9.add(rzList.get(18));  //认知19
        lisAudio9.add("07_A_05");  //行为5
        lisAudio9.add("10_A_01"); //唤醒

        //---------------------------第10天--------------------------
        List<String> lisAudio10 = new ArrayList<>();
        lisAudio10.add("01_A_00"); //指导语
        lisAudio10.add("01_A_02");  //低阻抗2
        lisAudio10.add(sel14.get(9));  //主症4-第二次
        lisAudio10.add(rzList.get(19));  //认知20
        lisAudio10.add(rzList.get(20));  //认知21
        lisAudio10.add("09_A_03"); //疗后体验3
        lisAudio10.add("10_A_01"); //唤醒

        //---------------------------第11天--------------------------
        List<String> lisAudio11 = new ArrayList<>();
        lisAudio11.add("01_A_00"); //指导语
        lisAudio11.add("01_A_01");  //低阻抗1
        lisAudio11.add(sel14.get(10));  //主症5-第一次
        lisAudio11.add(rzList.get(21));  //认知22
        lisAudio11.add(rzList.get(22));  //认知23
        lisAudio11.add("07_A_06");  //行为5
        lisAudio11.add("10_A_01"); //唤醒

        //---------------------------第12天--------------------------
        List<String> lisAudio12 = new ArrayList<>();
        lisAudio12.add("01_A_00"); //指导语
        lisAudio12.add("01_A_02");  //低阻抗2
        lisAudio12.add(sel14.get(11));  //主症5-第二次
        lisAudio12.add(rzList.get(23));  //认知24
        lisAudio12.add(rzList.get(24));  //认知25
        if (kgrNum > 1) {
            lisAudio12.add("06_A_02"); //抗干扰
        }

        lisAudio12.add("09_A_04"); //疗后体验4
        lisAudio12.add("10_A_01"); //唤醒

        //---------------------------第13天--------------------------
        List<String> lisAudio13 = new ArrayList<>();
        lisAudio13.add("01_A_00"); //指导语
        lisAudio13.add("01_A_01");  //低阻抗1
        lisAudio13.add(sel14.get(12));  //主症6-第一次
        lisAudio13.add(rzList.get(25));  //认知26
        lisAudio13.add(rzList.get(26));  //认知27
        lisAudio13.add("07_A_01");  //行为1
        lisAudio13.add("10_A_01"); //唤醒


        //---------------------------第14天--------------------------
        List<String> lisAudio14 = new ArrayList<>();
        lisAudio14.add("01_A_00"); //指导语
        lisAudio14.add("01_A_02");  //低阻抗2
        lisAudio14.add(sel14.get(0));  //主症1-第一次
        lisAudio14.add(rzList.get(27));  //认知1
        lisAudio14.add(rzList.get(28));  //认知2
        lisAudio14.add("09_A_01");  //疗后体验1
        lisAudio14.add("10_A_01"); //唤醒


        //---------------------------第15天--------------------------
        List<String> lisAudio15 = new ArrayList<>();
        lisAudio15.add("01_A_00"); //指导语
        lisAudio15.add("01_A_01");  //低阻抗1
        lisAudio15.add(sel14.get(1));  //主症1-第二次
        lisAudio15.add(rzList.get(29));  //认知3
        lisAudio15.add(rzList.get(30));  //认知4
        lisAudio15.add("07_A_01");  //行为1
        lisAudio15.add("08_A_01");  //信心增强
        lisAudio15.add("10_A_01"); //唤醒


        //---------------------------第16天--------------------------
        List<String> lisAudio16 = new ArrayList<>();
        lisAudio16.add("01_A_00"); //指导语
        lisAudio16.add("01_A_02");  //低阻抗2
        lisAudio16.add(sel14.get(2));  //主症1-第三次
        lisAudio16.add(rzList.get(31));  //认知5
        lisAudio16.add(rzList.get(32));  //认知6

        if (kgrNum > 0) {
            lisAudio16.add("06_A_01"); //抗干扰
        }

        lisAudio16.add("09_A_02"); //疗后体验2
        lisAudio16.add("10_A_01"); //唤醒


        //---------------------------第17天--------------------------
        List<String> lisAudio17 = new ArrayList<>();
        lisAudio17.add("01_A_00"); //指导语
        lisAudio17.add("01_A_01");  //低阻抗1
        lisAudio17.add(sel14.get(3));  //主症2-第一次
        lisAudio17.add(rzList.get(33));  //认知8
        lisAudio17.add(rzList.get(34));  //认知9
        lisAudio17.add("07_A_02");  //行为2
        lisAudio17.add("10_A_01"); //唤醒


        //---------------------------第18天--------------------------
        List<String> lisAudio18 = new ArrayList<>();
        lisAudio18.add("01_A_00"); //指导语
        lisAudio18.add("01_A_02");  //低阻抗2
        lisAudio18.add(sel14.get(4));  //主症2-第二次
        lisAudio18.add(rzList.get(35));  //认知8
        lisAudio18.add(rzList.get(36));  //认知9
        lisAudio18.add("09_A_03"); //疗后体验3
        lisAudio18.add("10_A_01"); //唤醒


        //---------------------------第19天--------------------------
        List<String> lisAudio19 = new ArrayList<>();
        lisAudio19.add("01_A_00"); //指导语
        lisAudio19.add("01_A_01");  //低阻抗1
        lisAudio19.add(sel14.get(5));  //主症2-第三次
        lisAudio19.add(rzList.get(37));  //认知10
        lisAudio19.add(rzList.get(38));  //认知11
        lisAudio19.add("07_A_03");  //行为3
        lisAudio19.add("08_A_01");  //信心增强
        lisAudio19.add("10_A_01"); //唤醒

        //---------------------------第20天--------------------------
        List<String> lisAudio20 = new ArrayList<>();
        lisAudio20.add("01_A_00"); //指导语
        lisAudio20.add("01_A_02");  //低阻抗2
        lisAudio20.add(sel14.get(6));  //主症3-第一次
        lisAudio20.add(rzList.get(39));  //认知8
        lisAudio20.add(rzList.get(40));  //认知9
        lisAudio20.add("09_A_04"); //疗后体验4
        lisAudio20.add("10_A_01"); //唤醒


        //---------------------------第21天--------------------------
        List<String> lisAudio21 = new ArrayList<>();
        lisAudio21.add("01_A_00"); //指导语
        lisAudio21.add("01_A_01");  //低阻抗1
        lisAudio21.add(sel14.get(8));  //主症4-第一次
        lisAudio21.add("09_A_01"); //疗后体验1
        if (kgrNum > 2) {
            lisAudio21.add("06_A_03"); //抗干扰
        }
        lisAudio21.add("07_A_04");  //行为2
        lisAudio21.add("08_A_01");  //信心增强
        lisAudio21.add("10_A_01"); //唤醒


        List<String> daysAudio = new ArrayList<>();
        daysAudio.add(AudioCureUtils.getTransAudio((String) lisAudio1.stream().collect(Collectors.joining(",", "", ""))));
        daysAudio.add(AudioCureUtils.getTransAudio((String) lisAudio2.stream().collect(Collectors.joining(",", "", ""))));
        daysAudio.add(AudioCureUtils.getTransAudio((String) lisAudio3.stream().collect(Collectors.joining(",", "", ""))));
        daysAudio.add(AudioCureUtils.getTransAudio((String) lisAudio4.stream().collect(Collectors.joining(",", "", ""))));
        daysAudio.add(AudioCureUtils.getTransAudio((String) lisAudio5.stream().collect(Collectors.joining(",", "", ""))));
        daysAudio.add(AudioCureUtils.getTransAudio((String) lisAudio6.stream().collect(Collectors.joining(",", "", ""))));
        daysAudio.add(AudioCureUtils.getTransAudio((String) lisAudio7.stream().collect(Collectors.joining(",", "", ""))));
        daysAudio.add(AudioCureUtils.getTransAudio((String) lisAudio8.stream().collect(Collectors.joining(",", "", ""))));
        daysAudio.add(AudioCureUtils.getTransAudio((String) lisAudio9.stream().collect(Collectors.joining(",", "", ""))));
        daysAudio.add(AudioCureUtils.getTransAudio((String) lisAudio10.stream().collect(Collectors.joining(",", "", ""))));
        daysAudio.add(AudioCureUtils.getTransAudio((String) lisAudio11.stream().collect(Collectors.joining(",", "", ""))));
        daysAudio.add(AudioCureUtils.getTransAudio((String) lisAudio12.stream().collect(Collectors.joining(",", "", ""))));
        daysAudio.add(AudioCureUtils.getTransAudio((String) lisAudio13.stream().collect(Collectors.joining(",", "", ""))));
        daysAudio.add(AudioCureUtils.getTransAudio((String) lisAudio14.stream().collect(Collectors.joining(",", "", ""))));
        daysAudio.add(AudioCureUtils.getTransAudio((String) lisAudio15.stream().collect(Collectors.joining(",", "", ""))));
        daysAudio.add(AudioCureUtils.getTransAudio((String) lisAudio16.stream().collect(Collectors.joining(",", "", ""))));
        daysAudio.add(AudioCureUtils.getTransAudio((String) lisAudio17.stream().collect(Collectors.joining(",", "", ""))));
        daysAudio.add(AudioCureUtils.getTransAudio((String) lisAudio18.stream().collect(Collectors.joining(",", "", ""))));
        daysAudio.add(AudioCureUtils.getTransAudio((String) lisAudio19.stream().collect(Collectors.joining(",", "", ""))));
        daysAudio.add(AudioCureUtils.getTransAudio((String) lisAudio20.stream().collect(Collectors.joining(",", "", ""))));
        daysAudio.add(AudioCureUtils.getTransAudio((String) lisAudio21.stream().collect(Collectors.joining(",", "", ""))));

        return daysAudio;
    }

    /**
     * 随机获取一条睡前催眠
     * @author wenliguo
     * @date 2025/6/9 14:04
     * @return com.sleep.psy.main_server.business2.evaluation.entity.PsyBaseVideo
     */
    private String selectSleepBaseVideo() {
        List<PsyBaseVideo> videos = psyBaseVideoService.selectBaseVideoByBsiType(MySqlConstant.PSY_BASE_VIDEO_BSI_TYPE_4);
        if (videos.isEmpty()) {
            return null;
        }
        return videos.get(new Random().nextInt(2)).getVideoUrl();

    }

}
